package zzps.exeed.kernel.aop;

import zzps.exeed.kernel.holder.MethodHolder;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Map;

public class InvocationHandlerImpl implements InvocationHandler {
    private Object target;
    private Map<Method, MethodHolder> methodHolderMap;

    public InvocationHandlerImpl(Object target,Map<Method, MethodHolder> methodHolderMap) {
        this.target = target;
        this.methodHolderMap = methodHolderMap;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        MethodHolder methodHolder = methodHolderMap.get(method);
        Invocation invocation = new InvocationImpl(target, methodHolder, args);
        return invocation.invoke();
    }
}
